/**************************************************************

Copyright Astrium Services GEO-Information / Spot Image
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

 ***************************************************************/
package com.spotimage.catalog.client.ui.component;

import com.smartgwt.client.types.HeaderControls;
import com.smartgwt.client.widgets.HeaderControl;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.spotimage.catalog.client.ui.Ui;

/**
 * Custom window
 */
public class MyWindow extends Window {
	
	/** default is modal window ? */
	private static final boolean DEFAULT_IS_MODAL = false;
	/** default is autosizing window ? */
	private static final boolean DEFAULT_AUTO_SIZE = true;
	/** default no background color ? */
	private static final boolean DEFAULT_NO_BACKGROUND_COLOR = false;

	/**
	 * 
	 */
	public MyWindow() {
		this(DEFAULT_AUTO_SIZE, DEFAULT_IS_MODAL, DEFAULT_NO_BACKGROUND_COLOR);
	}
	
	/**
	 * @param autoSize
	 */
	public MyWindow(boolean autoSize) {
		this(autoSize, DEFAULT_IS_MODAL, DEFAULT_NO_BACKGROUND_COLOR);
	}
	
	/**
	 * @param autoSize
	 * @param isModal
	 * @param noBackgroundColor
	 */
	public MyWindow(boolean autoSize, boolean isModal, boolean noBackgroundColor) {
		HeaderControl minimize = new HeaderControl(HeaderControl.MINIMIZE, new ClickHandler() {
			//@Override
			public void onClick(ClickEvent event) {
				minimize();
			}
		});
		HeaderControl maximize = new HeaderControl(HeaderControl.MAXIMIZE, new ClickHandler() {
			//@Override
			public void onClick(ClickEvent event) {
				restore();
			}
		});
		HeaderControl close = new HeaderControl(HeaderControl.CLOSE, new ClickHandler() {
			//@Override
			public void onClick(ClickEvent event) {
				destroy();
			}
		});
		setHeaderControls(HeaderControls.HEADER_LABEL, minimize, maximize, close);
		
		if (!noBackgroundColor) setBodyColor(Ui.BACKGROUND_COLOR);
		
		setAutoSize(autoSize);
		setAutoCenter(true);
		setCanDragReposition(true);
		setCanDragResize(true);
		setAnimateMinimize(true);
		
		if (isModal) {
			setIsModal(true);  
			setShowModalMask(true);  
			centerInPage();
		}
	}
	
}
